package com.qianyi.person.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.TransactionManagementConfigurer;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * @author tonypy
 * 2018/09/07
 * **/
//@Configuration
public class TransactionConfiguration implements TransactionManagementConfigurer{

    @Override
    public PlatformTransactionManager annotationDrivenTransactionManager() {
        return transactionManager;
    }

    @Resource(name = "transactionManger")
    private PlatformTransactionManager transactionManager;

    @Bean(name = "transactionManger")
    public PlatformTransactionManager getTransactionManager(DataSource dataSource){
        return  new DataSourceTransactionManager(dataSource);
    }
}
